﻿using Entity.Finance.DTO.IncomeManage;
using Entity.Finance.DTO.PayAccount;
using Entity.Finance.DTO.PayAccountItem;
using Entity.Finance.View.PayAccount;
using Entity.Finance.View.PayAccountItem;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service;
using Service.System;

namespace AnQinManagermentBackendAPI.Controller.Finance
{
    /// <summary>
    /// 报销单
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    [AllowAnonymous]
    public class PayAccountsController : ControllerBase
    {
        /**
         * 业务接口
         */
        private readonly PayAccountService _service;

        /**
         * 构造函数注入
         */
        public PayAccountsController(PayAccountService service)
        {
            _service = service;
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        [HttpGet]
        [ProducesResponseType(typeof(PayAccountView), 200)]
        public async Task<IActionResult> GetPayAccountList([FromQuery] PayAccountSearchDTO model)
        {
            var response = await _service.GetPayAccountList(model);
            return StatusCode(response.Status, response);
        }
        
        /// <summary>
        /// 获取子单列表
        /// </summary>
        [HttpGet("Item")]
        [ProducesResponseType(typeof(PayAccountItemView), 200)]
        public async Task<IActionResult> GetPayAccountItemList([FromQuery] PayAccountItemSearchDTO model)
        {
            var response = await _service.GetPayAccountItemList(model);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增
        /// </summary>
        [HttpPost]
        public async Task<IActionResult> AddPayAccount([FromBody] PayAccountAddDTO model)
        {
            var response = await _service.AddPayAccount(model);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 发起付款 创建付款单
        /// </summary>
        [HttpPost("Pay")]
        public async Task<IActionResult> Pay(PayManageAddDTO model)
        {
            var response = await _service.Pay(model);
            return StatusCode(response.Status, response);
        }


        /// <summary>
        /// 删除
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeletePayAccount([FromQuery] string Id)
        {
            var response = await _service.DeletePayAccount(Id);
            return StatusCode(response.Status, response);
        }

    }
}
